package org.example;


import org.example.segmentation.Range;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class DataSegmentation {

  public List<Range> getSegments(Connection sourceConn, String tableName, String segmentField, int segmentSize) throws SQLException {
    List<Range> segments = new ArrayList<>();
    String sql = String.format("SELECT MIN(%s), MAX(%s) FROM %s", segmentField, segmentField, tableName);
    try (Statement stmt = sourceConn.createStatement();
         ResultSet rs = stmt.executeQuery(sql)) {
      if (rs.next()) {
        long minValue = rs.getLong(1);
        long maxValue = rs.getLong(2);
        for (long i = minValue; i <= maxValue; i += segmentSize) {
//          segments.add(new Range(i, Math.min(i + segmentSize - 1, maxValue)));
        }
      }
    }
    return segments;
  }
}
